package com.example.shengyin.frontController;

import com.alibaba.fastjson2.JSON;
import com.example.shengyin.entity.Article;
import com.example.shengyin.entity.ArticleSimple;
import com.example.shengyin.entity.Page;
import com.example.shengyin.entity.Sym;
import com.example.shengyin.service.ArticleService;
import com.example.shengyin.service.SymService;
import com.example.shengyin.util.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.validation.BindingResult;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * AdminController
 * 
 * @author ruoyi
 * @date 2023-07-29
 */
@RestController
@RequestMapping("/front/infoactivites")
@Validated
@CrossOrigin(origins = "*", maxAge = 3600,allowCredentials="true")
//swagger
@Api(tags = "FrontInfoActivitiesController", description = "新闻活动，注意：活动讲座不要从这拿了，从前端活动里取")
public class FrontInfoActivitiesController
{
    @Autowired
    private ArticleService service;
    @Autowired
    private RedisTemplate redisTemplate;

    @ApiOperation("详细的新闻内容")
    @GetMapping(value = "/finddetail/{id}")
    public Result select(@ApiParam(name = "id",value = "编号") Long id)
    {
        Article article = service.selectById(id);
        System.out.println(JSON.toJSONString(article));
        if(article==null)
            return Result.error("没有找到数据");
        article.setVisittimes(article.getVisittimes()+1);
        service.update(article);
        return Result.success(article);
    }
    @ApiOperation("根据标题关键词查找")
    @PostMapping(value = "/selectword")
    public Result select2(@ApiParam(name = "typecode",value = "种类，例如：新闻活动、言语科普") @RequestParam(required = true) String typecode,
                          @ApiParam(name = "name",value = "关键词") @RequestParam(required = true) String name)
    {
        List<Article> article = service.selectByNmae(name,typecode,null);
        System.out.println(JSON.toJSONString(article));
        if(article==null)
            return Result.error("没有找到数据");
        return Result.success(article);
    }
    @ApiOperation("新闻活动->公司新闻")
    @PostMapping(value = "/findComnews")
    public Result findConmnews(@ApiParam(name = "page",value = "页数") @RequestParam(required = true) int page,
                               @ApiParam(name = "limit",value = "条数") @RequestParam(required = true) int limit)
    {
        Page page1=new Page(page,limit);
        int comnews = service.countTotall("公司新闻", null, null, null, null);
        List<ArticleSimple> articles = service.articleList2(page1, "公司新闻", null, null, null, null);
        if(comnews==0||articles==null)
            return Result.success(page,"没有数据");
        page1.setCount(comnews);
        page1.setData(articles);
        return Result.success(page1);
    }


    @ApiOperation("新闻活动->公司新闻->新闻分类  name对应英文名：开业活动->Opening 国际交流->International 员工活动->Staff  亲子交流->Parent-child   公益讲座->Public  公益活动->Interest 家长培训->Training 社会关注->Social 全部->不填")
    @PostMapping(value = "/findComnewstype")
    public Result findConmnews(@ApiParam(name = "page",value = "页数") @RequestParam(required = true) int page,
                               @ApiParam(name = "limit",value = "条数") @RequestParam(required = true) int limit,@ApiParam(name = "name",value = "分类名") @RequestParam(required = false)String name)
    {
        Page page1=new Page(page,limit);
        int comnews = service.countTotall("公司新闻", name, null, null, null);
        List<ArticleSimple> articles = service.articleList2(page1, "公司新闻", name, null, null, null);
        if(comnews==0||articles==null)
            return Result.success(page1,"没有数据");
        page1.setCount(comnews);
        page1.setData(articles);
        return Result.success(page1);
    }

    @ApiOperation("新闻活动->言语科普")
    @GetMapping(value = "/findSpeechs/{page}/{limit}")
    public Result findSpeechs(@PathVariable(value = "page") int page1,
                              @PathVariable(value = "limit")int limit)
    {
        Page page=new Page(page1,limit);
        int comnews = service.countTotall(null, "Speech", null, null, null);
        List<ArticleSimple> articles = service.articleList2(page, null, "Speech", null, null, null);
        if(comnews==0||articles==null)
            return Result.success(page,"没有数据");
        page.setCount(comnews);
        page.setData(articles);
        return Result.success(page);
    }
    @ApiOperation("新闻活动->活动讲座(热门推荐)")
    @GetMapping(value = "/findEventsTop")
    public Result findTop()
    {
        Page page=new Page(1,12);
        List<ArticleSimple> articles = service.articleList2(page, null, "Lecture", null, null, null);
        return Result.success(articles);
    }
    @ApiOperation("新闻活动->活动讲座(专题推荐)")
    @GetMapping(value = "/findEvents")
    public Result findSpecial()
    {
        Page page=new Page(1,12);
        List<ArticleSimple> articles = service.articleList3(page, null, "Lecture", null, null, null);
        return Result.success(articles);
    }

    @ApiOperation("新闻活动->活动讲座->热门点击(number是数据条数)")
    @GetMapping(value = "/Eventshot/{number}")
    public Result selecthot(@ApiParam(name = "number",value = "数据条数") int number)
    {
        List<ArticleSimple> article1 = service.Eventshot(number);
        return Result.success(article1);
    }
    @ApiOperation("新闻活动->活动讲座->最新发布(number是数据条数)")
    @GetMapping(value = "/Eventsnewest/{number}")
    public Result kepu_newest(@ApiParam(name = "number",value = "数据条数") int number)
    {
        List<ArticleSimple> article2 = service.Eventsnewwest(number);
        return Result.success(article2);
    }
    @ApiOperation("新闻活动->活动讲座->最多参与(number是数据条数)")
    @GetMapping(value = "/Eventsrecomend/{number}")
    public Result kepu_recomend(@ApiParam(name = "number",value = "数据条数") int number)
    {
        List<ArticleSimple> article2 = service.Eventsnewwest(number);
        return Result.success(article2);
    }

}
